<?php
include_once("../../../common/modules/checkA.php");
include_once("../../../../config.php");
include_once("../controller/plate-edit.php");


$act = isset($_REQUEST['act']) ? $_REQUEST['act'] : '';
$id  = isset($_REQUEST['id']) ? $_REQUEST['id']   : '0';


$coupon_list = select_lines_all_items($table_Prefix.'coupon','nid desc','is_delete = 0');


if($act == 'update')
{

	$table       = $table_Prefix ."coupon_plate";
	$detail_list = $_REQUEST;
    $coupon_data = [];


    if($_REQUEST['coupon_ids'])
    {
        foreach($_REQUEST['coupon_ids'] as $key=>$value)
        {
            if($_REQUEST['coupon_number'][$key] > 0){
                $coupon_data[$key]['id']     = $value;
                $coupon_data[$key]['number'] = $_REQUEST['coupon_number'][$key];
            }
        }
    }



        $detail_list['ai_coupon_ids'] = json_encode($coupon_data);



    //print_r2($detail_list);


	$sql = update_date($table,$detail_list,"nid",1);
	echo $sql;
	$res = do_query($sql);


	if($res)
	{
		echo '<script type="text/javascript">alert("修改成功");window.location.href="plate-edit.php?nav-itemed=coupon";</script>';
	}
	else
	    {
        echo '<script type="text/javascript">alert("修改失败");window.location.href="plate-edit.php?nav-itemed=couponscript>';
    }

}


?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <?php include ROOT_PATH_.'/controller/common/modules/head.php'; ?>
</head>

<body>


<div id="topbar">
    <?php include ROOT_PATH_.'/controller/common/modules/topbar.php'; ?>
</div>

<div id="container" class="<? echo $system_part ?>">

    <div id="maincontent">

        <div id="sidebar">
            <?php include ROOT_PATH_.'/controller/common/modules/sidebar.php'; ?>
        </div>


		<div id="content" class="layui-form">
            <?php $page_title='系统配置';?>
            <?php include ROOT_PATH_.'/controller/common/modules/mod-page-title.php'; ?>


            <div class="tips">
                1：新注册用户，会按照这个设置去送券，送的券都需要激活（分享激活，被邀请激活）。旧用户不受此设置影响。
            </div>



            <div class="detail-box member-edit-box layui-form">

                <div class="detail-boxes">
					<div class="detail-boxing">

					<form id="edit-member-form" method="post" action="plate-edit.php?act=update" class="layui-form">
 						  <input type="hidden" name="ai_nid" value="<? echo $detail['nid']?>">

                          <div class="layui-form-item">
                            <label class="layui-form-label">优惠券选择</label>
                            <div class="layui-input-block">
                                <?php
                                foreach($coupon_list as $coupon){
                                    $is_select = 0;
                                    $number = 0;
                                    foreach($detail['coupon_list'] as $d_coupon){

                                        if($d_coupon['id'] == $coupon['nid']){
                                            $is_select = 1;
                                            $number = $d_coupon['number'];
                                        }
                                    }
                                ?>
                                <div class="layui-input-block" style="margin-left:0">
                                    <input type="checkbox"  <?php echo  $is_select == 0 ? '' : "checked"; ?>  name="coupon_ids[<?php echo $coupon['nid']?>]" title="<?php echo $coupon['name']?>"   value="<?php echo $coupon['nid']?>" <?php echo $detail['coupon_id'] == $coupon['nid'] ? 'checked' : '' ; ?>>
                                    <input type="text"  style="height: 26px;position: relative;margin: 0 0 0 0px;top: 3px; width: 50px;" value="<?php echo $number;?>"  name="coupon_number[<?php echo $coupon['nid']?>]" /><span style="margin: 0 0 0 6px;display: inline-block;position: relative;top: 3px;">张</span>
                                </div>
                                    <?php

                                }
                                ?>
                            </div>
                          </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">优惠券分享开关</label>
                            <div class="layui-input-block">
                                <input  type="radio" name="ai_coupon_open" title="开启"  value="1" <?php echo $detail['coupon_open'] == 1 ? 'checked' : '' ; ?> >
                                <input type="radio" name="ai_coupon_open" title="关闭"  value="0"  <?php echo $detail['coupon_open'] == 0 ? 'checked' : '' ; ?>  >
                            </div>
                        </div>
                        <div class="layui-form-item">
                            <label class="layui-form-label">优惠券有效天数</label>
                            <div class="layui-input-block">
                                <input  class="layui-input" type="input" name="ai_expire_day"   value="<?php echo $detail['expire_day'];?>"  >
                                <div class="notice">有效天数以这个设置为准; 有效天数按照激活优惠券的时间开始计算。例：假设有效天数是7，A在一月一日注册拿到一张5折券，在6月一日再激活，这个有效时间就是6月1日+7天.</div>

                            </div>
                        </div>



                          <div class="layui-form-item">
                            <div class="layui-input-block">
                              <button class="layui-btn" lay-submit lay-filter="formMemberAdd" type="submit">立即提交</button>
                              <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                            </div>
                          </div>

					</form>
					</div>
				</div>
			</div>

<!--content端點01-->
</div>
<!--maincontent端點01-->
<br class="clearfloat"/>
</div>
<!--container端點01-->
</div>

<?php include ROOT_PATH_ . "/controller/common/modules/footer.php"; ?> </body>
</body>
</html>
